//package com.example.yk2021xm04.config;
//
///**
// * @author ZengQi
// * @description: TODO
// * @date 2021/12/8 0008 10:03
// */
//
//import com.fasterxml.jackson.core.JsonGenerator;
//import com.fasterxml.jackson.core.JsonParser;
//import com.fasterxml.jackson.databind.*;
//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//
//import java.io.IOException;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//
///**
// * 关于Java8中localDateTime去掉中间的T
// */
//@Configuration
//public class LocalDateTimeSerializerConfig {
////    @org.springframework.beans.factory.annotation.Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
////    private String pattern;
////
////    @Bean
////    public LocalDateTimeSerializer localDateTimeDeserializer() {
////        return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern));
////    }
////
////    @Bean
////    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
////        return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer());
////    }
//
//    @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
//    private String pattern;
//
//    @Bean
//    @Primary
//    public ObjectMapper serializingObjectMapper() {
//        ObjectMapper objectMapper = new ObjectMapper();
//        JavaTimeModule javaTimeModule = new JavaTimeModule();
//        javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
//        javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer());
//        objectMapper.registerModule(javaTimeModule);
//        return objectMapper;
//    }
//
//    public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
//        @Override
//        public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
//                throws IOException {
//            gen.writeString(value.format(DateTimeFormatter.ofPattern(pattern)));
//        }
//    }
//
//    public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
//        @Override
//        public LocalDateTime deserialize(JsonParser p, DeserializationContext deserializationContext)
//                throws IOException {
//            return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ofPattern(pattern));
//        }
//    }
//
//}
